<template>
	<view class="app">
		<view class="tabs" :class="ceiling ? 'fixed' : '' ">
			<view class="time-tab">
				<view class="seckill-tab">
					<span class="span">最后疯抢</span>
					<span class="em">已开抢</span>
					<span class="hot-icon"></span>
				</view>
				<view class="seckill-tab" v-for="(tab,tab_index) in seckillTabs" :key="tab_index" :class=" tab.id == '1' ? 'cur' : '' ">
					<span class="span">{{tab.data}}</span>
					<span class="em">{{tab.msg}}</span>
				</view>
			</view>
		</view>
		<view class="seckill-items">
			<view class="seckill-item" v-for="(item,item_index) in goods" :key="item_index">
				<view class="item">
					<view class="good-cover">
						<image :src="item.img" class="img"></image>
					</view>
					<view class="good-info">
						<view class="good-title">{{item.goodName}}</view>
						<view class="good-type">{{item.msg}}</view>
						<view class="sale">
							<view class="pics">
								<span class="cur-pic">
									<span class="dot">¥</span>
									<strong class="money">{{item.curPrice}}</strong>
								</span>
								<span class="pic">¥{{item.price}}</span>
							</view>
							<view class="detail" @click="goGoodDetail(item.id)">
								<button type="default">去抢购</button>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const tabs = [{
			id: "1",
			data: 1586592000000,
			msg: "抢购中"
		},
		{
			id: "2",
			data: 1586599200000,
			msg: "即将开始"
		}, {
			id: "3",
			data: 1586606400000,
			msg: "即将开始"
		}, {
			id: "4",
			data: 1586613600000,
			msg: "即将开始"
		}, {
			id: "5",
			data: 1586620800000,
			msg: "即将开始"
		},
	]
	const goodList = []

	import moment from 'moment';
	export default {
		data() {
			return {
				ceiling: false,
				scrollTop: 50,
				seckillTabs: [],
				goods: []
			}
		},
		onLoad() {
			
			this.seckillTabs = JSON.parse(JSON.stringify(tabs));
			let _self = this;
			let good;
			for (let i = 1; i <= 10; i++) {
				good = {
					id: i,
					goodName: '商品测试' + i,
					msg: '顺丰包邮',
					curPrice: 100,
					price: 200,
					img: 'http://m.360buyimg.com/babel/s333x333_jfs/t1/33728/10/12924/112345/5cf61386E2db7f1f0/81f13416b1522681.jpg!q70.dpg'
				}
				_self.goods.push(good);
			}
		},
		onPageScroll(e){
			this.ceiling = e.scrollTop >= this.scrollTop ? true : false;
		},
		mounted() {
		},
		watch: {
			seckillTabs() {
				this.seckillTabs.forEach(tab => {
					tab.data = moment(tab.data).format("HH:mm");
				})
			},
		},
		methods: {
			goGoodDetail(id){
				uni.navigateTo({
					url:`./good?id=${id}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	body {
		line-height: 1.2;
	}

	.tabs {
		top: 0;
		left: 0;
		right: 0;
		width: 100%;
		height: 120rpx;
		z-index: 998;
		max-width: 54rem;
		margin: 0 auto;
		font-size: 0;

		&.fixed {
			position: fixed;
			top: 0;
			box-shadow: 0 10rpx 16rpx 0 rgba(0, 0, 0, .06);
		}

		.time-tab {
			background-color: #fff;
			position: relative;
			white-space: nowrap;
			font-size: 0;
			font-family: arial;
			overflow-x: scroll;
			
			&::-webkit-scrollbar {
				width: 0;
				height: 0;
				background-color: transparent;
			}
			
			.seckill-tab {
				vertical-align: top;
				display: inline-block;
				height: 100%;
				padding: 30rpx 20rpx 10rpx 30rpx;
				overflow: hidden;
				text-align: center;
				font-size: 0;
				letter-spacing: 0;
				line-height: 28rpx;
				color: #333;

				&.cur {
					color: #ff4142;

					.em {
						background: linear-gradient(270deg, #ff4500, #ff1451);
						border-radius: 16rpx;
						padding: 4rpx;
						color: #fff;
						margin-top: 8rpx;
					}
				}

				.span {
					display: block;
					font-size: 11pt;
					line-height: 28rpx;
					font-family: JDZhengHT-EN-Bold;
					font-weight: 700;
				}

				.em {
					display: inline-block;
					margin-top: 10rpx;
					font-size: 9pt;
					letter-spacing: 0;
					text-align: center;
					line-height: 24rpx
				}

				.hot-icon {
					background-image: url();
					width: 1rem;
					height: 24rpx;
					background-size: contain;
					background-position: 50%;
					position: relative;
					top: .1rem;
					display: inline-block;
					margin-left: 10rpx;
					background-repeat: no-repeat;
				}
			}
		}
	}

	.seckill-items {
		padding-top: 40rpx;
		overflow: hidden;

		.seckill-item {
			position: relative;
			width: 700rpx;
			min-height: 280rpx;
			background: #fff;
			border-radius: 24rpx;
			margin: 20rpx auto 0;
			overflow: hidden;

			.item {
				padding: 20rpx;
				display: flex;

				.good-cover {
					width: 240rpx;
					height: 240rpx;

					.img {
						width: 100%;
						height: 100%;
						background-size: 100%;
					}
				}

				.good-info {
					display: flex;
					flex-direction: column;
					flex: 1;

					.good-title {
						color: #000000;
						font-weight: 400;
						line-height: 1.2;
						font-size: 11pt;
					}

					.good-type {
						margin-top: 16rpx;
						color: #F55C48;
						font-size: 9pt;
					}

					.sale {
						display: flex;
						flex: 1;
						align-items: flex-end;

						.pics {
							flex: 1;
							font-size: 0;

							.cur-pic {

								color: #F2270C;
								display: flex;
								align-items: center;
								.dot {
									font-size: 9pt;
								}
								.money {
									font-size: 17pt;
								}
							}

							.pic {
								margin-left: 8rpx;
								color: #bfbfbf;
								font-size: 9pt;
								text-decoration: line-through;
							}
						}

						.detail {
							
							button {
								font-size: 28rpx;
								background: linear-gradient(270deg, #ff1451, #ff4500);
								color: #fff;
								width: 160rpx;
								height: 80rpx;
								border-radius: 8rpx;
							}
						}
					}
				}
			}
		}
	}
</style>
